﻿namespace FlashcardPdfCreator
{
	using System.Collections.Generic;
	using System.Data.Common;
	using UsefulCode;

	public class DbCardDataProvider
	{
		public IEnumerable<ICardData> GetCardData()
		{
			return Db.ReadAndCast("Excel", GetExcel);
		}

		private IEnumerable<CardData> GetExcel(DbCommand command)
		{
			command.CommandText = "SELECT * FROM [Sheet1$]";

			using (DbDataReader reader = command.ExecuteReader())
			{
				while (reader.Read())
				{
					DbDataReaderCardData card = new DbDataReaderCardData(reader);
					yield return card; 
				}
			}
		}
	}
}
